<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        成品库库存信息编辑
    </h1>
    <a class="btn btn-info pull-right" shiro:hasPermission="halinv:halledgeredit:view"
       href="/half/halInvManage/InvInfoEdit/ledgerQuery" style="margin-right: 50px; margin-top: -25px;">
        台账查询</a>
</section>
<!--编辑模态框-->
<div class="modal fade" id="modal-editInv">
    <div class="modal-dialog" style="width: 450px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">库存信息编辑</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal">
                    <input type="hidden" id="ityId" name="ityId">
                    <input type="hidden" id="ityIds" name="ityIds">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">物料描述</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityMatName" name="ityMatName" class="form-control"
                                   readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">项目名称</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityProName" name="ityProName" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">部位名称</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityPart" name="ityPart" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">装箱日期</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityBoxingDate" name="ityBoxingDate" class="form-control datepicker">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">箱号</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityCaseNo" name="ityCaseNo" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityRemark" name="ityRemark" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">区位</label>
                        <div class="col-sm-9">
                            <input type="text" id="ityWhiName" name="ityWhiName" class="form-control">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-inv-commit">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <form id="queryForm">
                    <div class="box-header">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" id="ityProCode" name="ityProCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" id="ityProNameQuery" name="ityProNameQuery" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>部分名称</label>
                                    <input type="text" id="ityPart" name="ityPart" class="form-control"
                                           placeholder="请输入部分名称">
                                </div>
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" id="ityMatNameQuery" name="ityMatNameQuery" class="form-control"
                                           placeholder="请输入物料描述">
                                </div>
                                <div class="form-group">
                                    <label>SAP物料编码</label>
                                    <input type="text" id="itySapCode" name="itySapCode" class="form-control"
                                           placeholder="请输入SAP物料编码">
                                </div>

                                <div class="form-group">
                                    <label>图号</label>
                                    <input type="text" id="ityDrawingNumber" name="ityDrawingNumber"
                                           class="form-control" placeholder="请输入图号">
                                </div>
                                <div class="form-group">
                                    <label>箱号</label>
                                    <input type="text" id="ityCaseNoQuery" name="ityCaseNoQuery"
                                           class="form-control" placeholder="请输入箱号">
                                </div>
                                <div class="form-group">
                                    <label>区位</label>
                                    <input type="text" id="ityPositionQuery" name="ityPositionQuery"
                                           class="form-control" placeholder="请输入区位">
                                </div>
                                <div class="form-group">
                                    <label>在库类型</label>
                                    <select id="ityStockType" name="ityStockType" class="form-control">
                                        <option value="" selected>全部</option>
                                        <option value="2">项目在库</option>
                                        <option value="1">库存在库</option>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label>物料分类</label>
                                    <select id="ityMatType" name="ityMatType" class="form-control">
                                        <option value="" selected>全部</option>
                                        <!--<option value="1">外购件</option>-->
                                        <option value="3">制作件</option>
                                        <option value="2">外协件</option>
                                        <option value="4">铝料</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>库位</label>
                                    <select id="ityWhiIdQuery" name="ityWhiIdQuery" class="form-control">
                                        <option value="">全部</option>
                                        <option th:each="type:${warInfo}" th:value="${type.whiId}"
                                                th:text="${type.whiName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>装箱日期</label>
                                    <input type="text" class="form-control datepicker" id="startBoxingDateQuery"
                                           name="startBoxingDateQuery" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endBoxingDateQuery"
                                           name="endBoxingDateQuery" readonly="readonly"/>
                                </div>
                                <div class="form-group">
                                    <label>记账日期</label>
                                    <input type="text" class="form-control datepicker" id="startStorageDate"
                                           name="startStorageDate" readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" id="endStorageDate"
                                           name="endStorageDate" readonly="readonly"/>
                                </div>

                                <div class="form-group">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="row" id="toolbar">
                    <button shiro:hasPermission="halinv:halinvedit:edit" type="button"
                            class="btn btn-warning" id="btn-editItems">批量修改
                    </button>
                </div>
                <div class="box-body" style="text-align: center;">
                    <table id="bootstrap-table" style="word-break:break-all; word-wrap:break-all;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:src="@{/js/jquery.PrintArea.js}"></script>

<script th:inline="javascript">
    var table;
    var ids = [];

    function showQuery() {
        $("#queryHiddenDiv").show();
        $("#up").show();
        $("#down").hide();
    }

    function hiddenQuery() {
        $("#queryHiddenDiv").hide();
        $("#up").hide();
        $("#down").show();
    }

    /** 编辑按钮点击*/
    function editInv(id) {
        js.modal.open("modal-editInv");
        js.post({
            url: ctx + "half/halInvManage/InvInfoEdit/edit",
            data: {ityId: id},
            success: function (result) {
                $("#editForm").fillData(result.data.rows[0]);
            }
        })
    }

    function selectAll(obj) {
        if ($(obj).prop("checked")) {
            $('input[name="cb_inventory"]').prop("checked", true);
        }
        if ($(obj).prop("checked") == false) {
            $('input[name="cb_inventory"]').prop("checked", false);
        }
    }

    function openEditPanel(ids) {
        $("#editForm input[name='ityIds']").val(ids);
        $("#editForm")[0].reset();

        $("#editForm input[name='ityProName']").val("");
        $("#editForm input[name='ityPosition']").val("");
        $("#editForm input[name='ityRemark']").val("");

        js.modal.open("modal-editInv");
    }

    $(function () {

        /** 加载表格 */
        table = js.table.init({
            url: ctx + "half/halInvManage/InvInfoEdit/list",
            queryForm: "queryForm",
            clickToSelect: true,
            showExport: false,
            pageSize: 300,
            columns: [
                {
                    title: '<input  onclick="selectAll(this)" type="checkbox" />',
                    width: '30',
                    field: 'ityDataStatus',
                    formatter: function (value, row, index) {
                        var ityDataStatus = "";
                        ids.push('cb_inventory_' + row.ityId);
                        return '<input ' + ityDataStatus + ' id="' + 'cb_inventory_' + row.ityId + '" name="cb_inventory" data="' + row.ityId + '"  type="checkbox" />';
                    }
                },
                {
                    title: '序号', field: 'ityId', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {
                    title: "物料分类", field: 'ityMatType', width: '70',
                    formatter: function (value, row, index) {
                        if (row.ityMatType == 1) {
                            return "外购件"
                        } else if (row.ityMatType == 2) {
                            return "外协件"
                        } else if(row.ityMatType == 3){
                            return "制作件"
                        } else if(row.ityMatType == 4){
                            return "铝料"
                        }
                    }
                },
                {title: "物料描述<BR>（铝料类型）", field: 'ityMatName'},
                {title: "SAP<BR>物料编码", field: 'itySapCode', width: '70'},
                {
                    title: "图号<BR>（铝料模具号）", field: 'ityDrawingNumber', width: '80',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = ""
                        }
                        return value;
                    }
                },
                {title: "数量", field: 'ityNum', width: '40'},
                {title: "单位", field: 'ityUnit', width: '40'},
                {title: "跟踪号", field: 'ityTrackCode'},
                // {title: "品牌", field: 'ityBrand'},
                /*{
                    title: "在库类型", field: 'ityStockType',width:'80',
                    formatter: function (value, row, index) {
                        if (row.ityStockType == 1) {
                            return "库存在库"
                        } else if (row.ityStockType == 2) {
                            return "项目在库"
                        } else {
                            return row.ityStockType
                        }
                    }
                },*/
                {title: "项目编号", field: 'ityProCode', width: '100'},
                {title: "项目名称", field: 'ityProName', width: '80'},
                {title: "部分名称", field: 'ityPart', width: '90'},
                //{title: "仓库", field: 'ityWhiName', width: '60'},
                {title: "箱号", field: 'ityCaseNo'},
                {title: "装箱日期", field: 'ityBoxingDate', width: '90'},
                {title: "库位", field: 'ityWhiName', width: '60'},
                {title: "区位", field: 'ityPosition', width: '60'},
                {title: "记账日期", field: 'ityStorageDate', width: '90'},
                {title: "备注", field: 'ityRemark'},
                {
                    title: "操作", width: '110',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('halinv:halinvedit:edit')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="editInv(' + row.ityId + ')"> 编辑</a> ');
                        }
                        if (hasP('halinv:halledgeredit:view')) {
                            actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'half/halInvManage/InvInfoEdit/ledger/' + row.ityId + '"> 台账</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        // 搜索
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 保存库存信息*/
        $("#btn-inv-commit").click(function () {
            var b = $("#editForm").serialize();
            if ($("#ityMatName").val() == "") {
                js.post(
                    {
                        url: ctx + 'half/halInvManage/InvInfoEdit/invCommits',
                        data: $("#editForm").serialize(),
                        success: function (result) {
                            js.modal.hide("modal-editInv");
                            js.table.refresh(table);
                        },
                        dataType: 'json'
                    }
                );
            } else {
                js.submit({
                    url: ctx + "half/halInvManage/InvInfoEdit/invCommit",
                    data: new FormData($("#editForm")[0]),
                    success: function (result) {
                        js.modal.hide("modal-editInv");
                        js.table.refresh(table);
                    }
                })
            }
        });

        /** 点击批量修改事件*/
        $("#btn-editItems").click(function () {
            var ityIds = "";
            $('input[name="cb_inventory"]').each(function (index, data) {
                if ($(this).prop("checked")) {
                    ityIds += $(this).attr("data") + ",";
                }
            });
            ityIds = ityIds.substring(0, ityIds.length - 1);
            if (ityIds == "") {
                js.modal.warning("请选择要修改的数据！");
                return
            }
            openEditPanel(ityIds);
        });

    });

</script>
</body>
</html>